using System;
using System.Net;
using System.Net.Sockets;

namespace LANamp
{
	/// <summary>
	/// LANamp client object
	/// </summary>
	public class Client
	{
		private string ipaddress;
        private string hostname;
		private string server;
		private string nickname;
        private string version;
        private bool skipVote;
        private Socket serverSocket;
		private int lives;
		public static String ToIP(EndPoint ep)
		{
			return ep.ToString().Split(':')[0];
		}

		public Client(String IPaddress, String Server, String Nickname, String Hostname, String Version, int Lives)
		{
			ipaddress = IPaddress;
			nickname = Nickname;
            hostname = Hostname;
            version = Version;
			lives = Lives;
			server = Server;
            skipVote = false;
		}

        ~Client()
        {
            if (serverSocket != null) if (serverSocket.Connected) serverSocket.Close();
        }
		public String Nickname
		{
			get 
			{
				return nickname;
			}
			set
			{
				nickname = value;
			}
		}
        public String Hostname
        {
            get
            {
                return hostname;
            }
            set
            {
                hostname = value;
            }
        }
        public String Host
        {
            get
            {
                return (hostname != "") ? hostname.ToLower() + "  (" + ipaddress + ")" : ipaddress;
            }
        }
        public String IPaddress
		{
			get
			{
				return ipaddress;
			}
		}
        public string Version
        {
            get
            {
                return version;
            }
        }
		public String Server
		{
			get
			{
				return server;
			}
			set
			{
				server = value;
			}
		}
		public int Lives
		{
			get
			{
				return lives;
			}
			set
			{
				lives = value;
			}
		}
        public bool SkipVote
        {
            get
            {
                return skipVote;
            }
            set
            {
                skipVote = value;
            }
        }

        public void DoSkipVote()
        {
            if (serverSocket != null) skipVote = true;
        }

        public void ClearSkipVote()
        {
            skipVote = false;
        }

        public Socket ServerSocket
        {
            get
            {
                return serverSocket;
            }
            set
            {
                if (serverSocket != null) if (serverSocket.Connected) serverSocket.Disconnect(true);
                if (value.Connected) serverSocket = value;
            }
        }
	}
}
